//
// Created by guanzhe on 15/12/31.
// Copyright (c) 2015 BMProject. All rights reserved.
//

#import "MsgCell.h"
#import "DataModel.h"
#import "UIColor+Extension.h"
#import "JSONModel+networking.h"
#import "NSDate+Utils.h"

@interface MsgCell(){
    MsgModel *_model;
}

@property (weak, nonatomic) IBOutlet UIView *bgView;
@property (weak, nonatomic) IBOutlet UILabel *titleLabel;
@property (weak, nonatomic) IBOutlet UILabel *msgLabel;
@property (weak, nonatomic) IBOutlet UILabel *isReadLabel;
@property (weak, nonatomic) IBOutlet UILabel *timeLabel;
@property (weak, nonatomic) IBOutlet UILabel *receivePerLabel;
@property (weak, nonatomic) IBOutlet UIButton *repairBtn;
@property (weak, nonatomic) IBOutlet UIButton *deleteBtn;

@end

@implementation MsgCell {

}
- (IBAction)repairAction:(id)sender {
    [self.delegate clickActionWithData:_model AndType:@"repair"];
}
- (IBAction)deleteAction:(id)sender {
    [self.delegate clickActionWithData:_model AndType:@"delete"];
}

- (void)setCellInfo:(NSArray *)infoArr andPosition:(NSInteger)position {
    [super setCellInfo:infoArr andPosition:position];
    _model = [infoArr objectAtIndex:position];
    MsgModel *msgModel = [infoArr objectAtIndex:position];
    self.bgView.layer.cornerRadius = 5.0;
    self.bgView.layer.masksToBounds = YES;
    self.titleLabel.text = [@"消息标题:" stringByAppendingString:[NSString ignoreEmptyStr:msgModel.title]];
    NSMutableAttributedString *contentString;
    contentString = [[NSMutableAttributedString alloc] initWithString:[@"消息内容:" stringByAppendingString:[NSString ignoreEmptyStr:msgModel.message]]];
    [contentString addAttribute:NSForegroundColorAttributeName value:[UIColor hexValue:0x333333] range:NSMakeRange(5, msgModel.message.length)];
    self.msgLabel.attributedText = contentString;

    NSMutableAttributedString *isReadString;
    NSString *isRead = [@"1" isEqualToString:msgModel.sign] ? @"已读" : @"未读";
    isReadString = [[NSMutableAttributedString alloc] initWithString:[@"是否阅读:" stringByAppendingString:[NSString ignoreEmptyStr:isRead]]];
    [isReadString addAttribute:NSForegroundColorAttributeName value:[UIColor hexValue:0x333333] range:NSMakeRange(5, isRead.length)];
    self.isReadLabel.attributedText = isReadString;

    NSMutableAttributedString *receiveNameString;
    receiveNameString = [[NSMutableAttributedString alloc] initWithString:[@"接收人:" stringByAppendingString:[NSString ignoreEmptyStr:msgModel.recUserId]]];
    [receiveNameString addAttribute:NSForegroundColorAttributeName value:[UIColor hexValue:0x333333] range:NSMakeRange(4, msgModel.recUserId.length)];
    self.receivePerLabel.attributedText = receiveNameString;

    NSMutableAttributedString *timeString;
    NSString *time = [[NSDate dateWithString:msgModel.creatTime formatString:@"yyyyMMddHHmmss"] formatStringWithFormat:@"yyyy-MM-dd"];
    timeString = [[NSMutableAttributedString alloc] initWithString:[@"发布时间:" stringByAppendingString:[NSString ignoreEmptyStr:time]]];
    [timeString addAttribute:NSForegroundColorAttributeName value:[UIColor hexValue:0x333333] range:NSMakeRange(5, time.length)];
    self.timeLabel.attributedText = timeString;
}


@end